<template>
  <div class="login-wrap">
        <div class="ms-login">
            <div class="ms-title">西餐厅后台管理系统</div>
            <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0px" class="ms-content">
                <el-form-item prop="username">
                    <el-input v-model="loginForm.userName" placeholder="用户名">
                        <el-button slot="prepend" icon="username"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password" placeholder="密码" v-model="loginForm.password" @keyup.enter.native="handleLogin">
                        <el-button slot="prepend" icon="password"></el-button>
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="danger" @click.native.prevent="handleLogin">登录</el-button>
                </div>
                <p class="login-tips">Tips : Have a nice day! haaaaah~~~</p>
            </el-form>
        </div>
    </div>
  
</template>
<script>
  export default {
    name: 'login',
    data() {
      return {
        loginForm: {
          userName: '',
          password: ''
        },
        loginRules: {
          userName: [{required: true, trigger: 'blur', message: "请输入用户名"}],
          password: [{required: true, trigger: 'blur', message: "请输入密码"}]
        },
        loading: false,
      }
    },
    methods: {
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.loading = true
            this.$store.dispatch('Login', this.loginForm).then(data => {
              this.loading = false
              this.$router.push({path: '/'})
            }).catch(() => {
              this.loading = false
            })
          } else {
            return false
          }
        })
      }
    }
  }
</script>
<style rel="stylesheet/scss" lang="scss">
    .login-wrap{
        position: relative;
        width:100%;
        height:100%;
        background-image: url(../../assets/login2.jpg);
        -moz-background-size:100% 100%; background-size:100% 100%;
    }
    .ms-title{
        width:100%;
        line-height: 50px;
        text-align: center;
        font-size:25px;
        color: #fff;
        border-bottom: 1px solid #ddd;
    }
    .ms-login{
        position: absolute;
        left:50%;
        top:50%;
        width:350px;
        margin:-190px 0 0 -175px;
        border-radius: 5px;
        background: rgba(255,255,255, 0.3);
        overflow: hidden;
    }
    .ms-content{
        padding: 30px 30px;
    }
    .login-btn{
        text-align: center;
    }
    .login-btn button{
        width:100%;
        height:36px;
        margin-bottom: 10px;
    }
    .login-tips{
        font-size:12px;
        line-height:30px;
        color:rgb(240, 34, 96);
    }
</style>
